/***************************************************************************
 *   Copyright (C) 2007 by Harm van Eersel                                 *
 *   devsciurus@xs4all.nl                                                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include <QDialog>
#include <QDialogButtonBox>
#include <QVBoxLayout>
#include <QGroupBox>
#include <QLabel>
#include <QLineEdit>
#include <QCheckBox>

#include "settings.h"
#include "molscene.h"

SettingsDialog::SettingsDialog(MolScene* scene, QWidget * parent, Qt::WindowFlags f ) : QDialog(parent,f), m_scene(scene)
{
  // Setup the user interface
  ui.setupUi(this);
  ui.groupBoxAtom->setTitle(tr("Atom settings"));
  ui.groupBoxBond->setTitle(tr("Bond settings"));

//   ui.labelAtomSize->setText(tr("Atom size: "));
  ui.labelBondLength->setText(tr("Bond length: "));
  ui.labelBondAngle->setText(tr("Bond angle: "));

//   ui.lineEditAtomSize->setText(QString::number(scene->atomSize()));
  ui.lineEditBondLength->setText(QString::number(scene->bondLength()));
  ui.spinBoxBondAngle->setValue(scene->bondAngle());

  ui.checkBoxAutoHydrogen->setText(tr("Automatic add hydrogens"));
  if (scene->autoAddHydrogen()) ui.checkBoxAutoHydrogen->setCheckState(Qt::Checked);
  ui.checkBoxShowCarbon->setText(tr("Show neutral carbon atoms"));
  if (scene->carbonVisible()) ui.checkBoxShowCarbon->setCheckState(Qt::Checked);
  ui.checkBoxShowHydrogen->setText(tr("Show neutral hydrogen atoms"));
  if (scene->hydrogenVisible()) ui.checkBoxShowHydrogen->setCheckState(Qt::Checked);
  ui.checkBoxShowValency->setText(tr("Show atom charge"));
  if (scene->chargeVisible()) ui.checkBoxShowValency->setCheckState(Qt::Checked);
}

SettingsDialog::~ SettingsDialog( )
{

}

void SettingsDialog::accept()
{
	// Line edits
// 	m_scene->setAtomSize(ui.lineEditAtomSize->text().toDouble());
	m_scene->setBondLength(ui.lineEditBondLength->text().toDouble());
	m_scene->setBondAngle(ui.spinBoxBondAngle->text().toInt());
	
	// Checkboxes
	m_scene->setAutoAddHydrogen(ui.checkBoxAutoHydrogen->isChecked());
	m_scene->setCarbonVisible(ui.checkBoxShowCarbon->isChecked());
	m_scene->setHydrogenVisible(ui.checkBoxShowHydrogen->isChecked());
	m_scene->setChargeVisible(ui.checkBoxShowValency->isChecked());
	
	// Close dialog
	QDialog::accept();
}
